import cv2
import numpy as np

def add(img):

    while True:
        cv2.namedWindow('img', cv2.WINDOW_AUTOSIZE)
        logo = cv2.imread('./img/1220.png')
        logo = cv2.resize(logo, (300, 100))
        b, g, r = cv2.split(logo)
        mask = np.zeros(b.shape, np.uint8)
        mask[:, :] = 0
        mask[b > 200] = 255
        logo[b > 200] = 0
        # 选择图像位置
        roi = img[0: 100, 0: 300]  
        tmp = cv2.bitwise_and(roi, roi, mask=mask)
        dst = cv2.add(tmp, logo)
        img[0: 100, 0: 300] = dst

        cv2.imshow('img', img)    
        key = cv2.waitKey(10)
        if key & 0xFF == ord('q'):
            cv2.destroyAllWindows()
            break
        elif key == ord('s'):
            cv2.imwrite('./img/newadd.png', img)
            cv2.destroyAllWindows()
            break
        if cv2.getWindowProperty('img', cv2.WND_PROP_VISIBLE) <= 0:
            break
